﻿using System;

namespace RRRSRoguelike.Helpers.Visualizer
{
	/// <summary>
	/// Something to do with drawing the dungeon.
	/// </summary>
	public struct DungeonSquare
	{
		//HACK: this is consoleSpecific
		/// <summary>
		/// character to display
		/// </summary>
		public string character;
		/// <summary>
		/// color
		/// </summary>
		public ConsoleColor color;
		/// <summary>
		/// background color
		/// </summary>
		public ConsoleColor background;
	}
	/// <summary>
	/// Preserves the layers of the dungeon as the player traverses the layers.
	/// Gathers squares of the dungeon and updates necessary squares prior to 
	/// rendering the current view of the layer to the screen.
	/// </summary>
	public class Layer
	{
		
		/// <summary>
		/// for drawing dungeon
		/// </summary>
		public DungeonSquare[,] DungeonSquares;

		/// <summary>
		/// for preventing redrawing
		/// </summary>
		public DungeonSquare[,] OldDungeonSquares;

		/// <summary>
		/// constructor
		/// </summary>
		public Layer()
		{
			DungeonSquares = new DungeonSquare[Constants.DungeonWidth, Constants.DungeonHeight];

			OldDungeonSquares = new DungeonSquare[Constants.DungeonWidth, Constants.DungeonHeight];
		}

		
		/// <summary>
		/// constructor
		/// </summary>
		public Layer(int width, int height)
		{
			DungeonSquares = new DungeonSquare[width, height];

			OldDungeonSquares = new DungeonSquare[width, height];
		}

		
		/// <summary>
		/// returns true if dungeon square has changed at coordinates.
		/// </summary>
		public bool HasChanged(int x, int y)
		{
			return DungeonSquares[x, y].character != OldDungeonSquares[x, y].character ||
			       DungeonSquares[x, y].color != OldDungeonSquares[x, y].color;
		}

		
		/// <summary>
		/// Clears the oldDungeonSquares record
		/// </summary>
		public void ClearOldSquares()
		{
			OldDungeonSquares = new DungeonSquare[Constants.DungeonWidth, Constants.DungeonHeight];
		}

		/// <summary>
		/// Records a copy of the current dungeon squares into OldDungeonSquares
		/// </summary>
		public void RecordOldSquares()
		{
			OldDungeonSquares = (DungeonSquare[,])DungeonSquares.Clone();
		}
	}
}
